package com.vimi8.ebb.service;

import com.vimi8.ebb.dto.CategoryDto;
import com.vimi8.ebb.dto.EnumCategoryDto;
import com.vimi8.ebb.model.EnumCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by wangguiyin on 2016/9/8.
 * 枚举分类表service
 */
@Mapper
public interface EnumCategoryService {

    /**
     * 按id查询枚举分类信息
     * @param id(此处id是通过拆分得到的10__000000字符串  使用模糊查询可得到相应的分类)
     * @return
     */
    @Select("select id,category_name as categoryName,order_num as orderNum,category_icon as categoryIcon,category_level as categoryLevel from enum_category where " +
            " id like CONCAT('%',#{id},'%') and id!= #{categoryId}")
    public List<EnumCategory> getEnumCategoryListtById(@Param("id") String id, @Param("categoryId") String categoryId);


    @Select("select id,category_name as categoryName,order_num as orderNum,category_icon as categoryIcon from enum_category where " +
            " id=#{id}")
    public EnumCategory getEnumCategory(@Param("id") String id);
    /**
     * 按id查询枚举分类信息
     * @param id(根据id返回品类对象)
     * @return
     */
    @Select("select id,category_name as categoryName,category_level as categoryLevel,order_num as orderNum,category_icon as categoryIcon from enum_category where " +
            " id= #{id}")
    public EnumCategory getEnumCategoryById(@Param("id") String id);


    /**
     * 添加枚举分类信息
     * @param enumCategory
     * @return
     */
    @Insert("insert into enum_category(id,category_name,category_level,order_num,category_icon) values(#{id},#{categoryName},#{categoryLevel},#{orderNum},#{categoryIcon});")
    public int insertEnumCategory(EnumCategory enumCategory);


    /**
     * 修改枚举分类信息
     * @param enumCategory
     * @return
     */
    @Update("update enum_category set id=#{id},category_name=#{categoryName},order_num=#{orderNum},category_icon=#{categoryIcon} " +
            "where id=#{id}")
    public int updateEnumCategory(EnumCategory enumCategory);

    /**
     * 删除枚举分类信息
     * @param id
     * @return
     */
    @Delete("delete from enum_category where id=#{id}")
    public int deleteEnumCategory(String id);

    /**
     * 按id查询枚举分类信息
     * @param id(此处id是通过拆分得到的10__000000字符串  使用模糊查询可得到相应的分类)
     * @return
     */
    @Select("select id,category_name as categoryName,order_num as orderNum,category_icon as categoryIcon,category_level as categoryLevel from enum_category where " +
            " id like CONCAT('%',#{id},'%') and id!= #{categoryId}")
    public List<CategoryDto> getEnumCategoryListById(@Param("id") String id, @Param("categoryId") String categoryId);

    /**
     * 按id查询枚举分类信息
     * @return
     */
    @Select("select id,category_name as categoryName,category_level as categoryLevel,order_num as orderNum,category_icon as categoryIcon from enum_category where " +
            " id like CONCAT('10','%')")
    public List<EnumCategory> getFarmCategory();

    @Select("select id,category_name as categoryName,order_num as orderNum,category_icon as categoryIcon,category_level as categoryLevel from enum_category where " +
            " id like CONCAT('%',#{id},'%') and id!= #{categoryId}")
    public List<EnumCategoryDto> getEnumCategoryList(@Param("id") String id, @Param("categoryId") String categoryId);

    @Select("select count(1) from product_info where enum_category_id like CONCAT('%',#{id},'%')")
    public int getCountByProduct(@Param("id") String id);

    @Select("select count(1) from farm_info where enum_category_id like CONCAT('%',#{id},'%') ")
    public int getCountByFarm(@Param("id") String id);

    /**
     * 根据分类名称查询
     * @param name 分类名称
     * @return
     */
    @Select("SELECT id, category_name AS categoryName, category_level AS categoryLevel, order_num AS orderNum, " +
            "category_icon AS categoryIcon " +
            "FROM enum_category WHERE category_name=#{name}")
    public List<EnumCategory> getCategoryByName(String name);

    /**
     * 根据分类名称查询
     * @param min 最小值
     * @param max 最大值
     * @return
     */
    @Select("SELECT id, category_name AS categoryName, category_level AS categoryLevel, order_num AS orderNum, " +
            "category_icon AS categoryIcon " +
            "FROM enum_category WHERE id BETWEEN #{min} AND #{max} and id!=#{min} and id!=#{max}")
    public List<EnumCategory> getCategoryByRange(@Param("min")String min, @Param("max")String max);
}



